mui.init({
	pullRefresh: {
		container: "#refreshContainer", //下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
		down: {
			style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
			color: '#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
			height: '50px', //可选,默认50px.下拉刷新控件的高度,
			range: '100px', //可选 默认100px,控件可下拉拖拽的范围
			offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
			auto: false, //可选,默认false.首次加载自动上拉刷新一次
			callback: pullDown_refresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
		}
	}
});
var class_data;
var search_result;
mui.plusReady(function () {
	hideScrollBar();
    class_data = new Vue({
        el: '#search',
        data: {
            lists:[],
            cate_list:[],
            category:'',
            district:'',
            price:'',
            cate_id:'',
            price_index:'', 
            current: 0,
            auditStatus:'no',
        },
        mounted(){
            var self = this;
            this.get_class_lists();
            this.get_cate_list();
            this.$nextTick(function () {
                self.auditStatus = plus.storage.getItem('auditStatus') ? plus.storage.getItem('auditStatus') : 'no';
            })
        },
        methods: {
            get_class_lists:function () {
                showWatting();
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url:api_host+'/api/course/course/courseslist?time='+Date.parse(new Date()),
                    dataType:'json',
                    type:'get',
                    timeout:1000,
                    
                    success:function(msg){
                        class_data.lists = msg.data;
                    },
                    error:function () {
                        console.log('课程列表获取出错了');
                    },
                    complete: function() {
                        plus.nativeUI.closeWaiting();
                    }
                })
            },
            get_cate_list:function(){
            	var api_host = plus.storage.getItem('HOST_URL');
            	mui.ajax({
            		url:api_host +'/api/course/course/categoriesList?time='+Date.parse(new Date()),
            		dataType:'json',
            		type:'get',
            		timeout:1000,
            		success:function(msg){
            			class_data.category = msg.data.category;
            			class_data.district = msg.data.district;
            			class_data.price = msg.data.price;
            		},
            		error:function () {
                        console.log('获取分类列表失败!');
                   },
                   complete: function() {
                        plus.nativeUI.closeWaiting();
                    }
            	})
            },
            open_class_detils:function (classid) {
                mui.openWindow({
                    url:'../courseDetail/courseDetail.html',
                    extras:{'cid':classid},
                    createNew:false,
                    show:{
                        autoShow:true,
                        anishow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                    	autoShow: false,
                    }
                });
            },
            open_search:function() {
            	$('.popMask').show();
            	$('.popFilter').animate({
			   		'right': '0%'
			   	}, 200);
            },
            confirmBtn:function() {
            	var api_host = plus.storage.getItem('HOST_URL');
            	mui.ajax({
            		url:api_host+'/api/course/course/courseSearch',
            		dataType:'json',
            		 data:{'categoryId':class_data.cate_id},
            		type:'get',
            		timeout:5000,
            		success:function(msg){
            			if(msg.code == 1) {
	        					class_data.lists = msg.data.resources;
	        				}else{
	        					class_data.lists = null;
	        				}
            		}
            	})
            	
            	$('.popMask').hide();
			   	$('.popFilter').animate({
			   		'right': '-90%'
			   	}, 200);
          },
           selected_cate:function(e,index) {
           		class_data.cate_id = e.target.getAttribute('cate_id');
         		this.current = index;
           },
           selected_price:function(e) {
           		class_data.price_index = e.target.getAttribute('price');
           }
        }
    });
});

function pullDown_refresh() {
	class_data.get_class_lists();
	setTimeout(function() {
		mui("#refreshContainer").pullRefresh().endPulldownToRefresh(false);
	},1000);
}
